package com.zjsru.plan2024.codeBase.fifty;

/**
 * 896. 单调数列
 * @Author: cookLee
 * @Date: 2024-06-30
 */
public class IsMonotonic {

    /**
     * 主
     * \
     * 输入：nums = [1,2,2,3]
     * 输出：true
     * \
     * 输入：nums = [6,5,4,4]
     * 输出：true
     * \
     * 输入：nums = [1,3,2]
     * 输出：false
     * \
     * @param args args
     */
    public static void main(String[] args) {
        IsMonotonic isMonotonic = new IsMonotonic();
        int[] nums = new int[]{1,3,2};
        System.out.println(isMonotonic.isMonotonic(nums));
    }

    /**
     * 模拟
     *
     * @param nums nums
     * @return boolean
     */
    public boolean isMonotonic(int[] nums) {
        int len = nums.length;
        boolean increase = true;
        //判断增长
        for (int i = 1; i <= len - 1; i++) {
            if (nums[i] < nums[i - 1]) {
                increase = false;
            }
        }
        if(!increase){
            //判断递减
            for (int i = 1; i <= len - 1; i++) {
                if (nums[i] > nums[i - 1]) {
                    return false;
                }
            }
        }
        return true;
    }
}
